#pragma once

#include <sys_reg.h>

typedef enum {
	TIMER0_Q = 0x40012C00,
	TIMER1_Q = 0x40000000,
	TIMER2_Q = 0x40000400,
	TIMER3_Q = 0x40000800,
	TIMER4_Q = 0x40000C00,
	TIMER5_Q = 0x40001000,
	TIMER6_Q = 0x40001400,
} timer_qe;

typedef enum {
	TIMER_CTL0_R = 0x0,
	TIMER_CTL1_R = 0x4,
	TIMER_SMCFG_R = 0x8,
	TIMER_DMAINTEN_R = 0xC,
	TIMER_INTF_R = 0x10,
	TIMER_SWEVG_R = 0x14,
	TIMER_CHCTL0_R = 0x18,
	TIMER_CHCTL1_R = 0x1C,
	TIMER_CHCTL2_R = 0x20,
	TIMER_CNT_R = 0x24,
	TIMER_PSC_R = 0x28,
	TIMER_CAR_R = 0x2C,
	TIMER_CREP_R = 0x30,
	TIMER_CH0CV_R = 0x34,
	TIMER_CH1CV_R = 0x38,
	TIMER_CH2CV_R = 0x3C,
	TIMER_CH3CV_R = 0x40,
	TIMER_CCHP_R = 0x44,
	TIMER_DMACFG_R = 0x48,
	TIMER_DMATB_R = 0x4C,
} timer_re;

static inline u32_s timer_get_reg_q(timer_qe timer_q, timer_re timer_r,
				    u32_s byte_r) {
	return timer_q + timer_r + byte_r;
}

static inline void timer_wreg(timer_qe timer_q, timer_re timer_r, u32_s value) {
	u32_s reg_q = timer_get_reg_q(timer_q, timer_r, 0);
	wreg(reg_q, value);
}

static inline void timer_wreg_u16(timer_qe timer_q, timer_re timer_r,
				  t16b_re byte_r, u32_s value) {
	u32_s reg_q = timer_get_reg_q(timer_q, timer_r, byte_r);
	wreg_u16(reg_q, value);
}

static inline u32_s timer_rreg(timer_qe timer_q, timer_re timer_r) {
	u32_s reg_q = timer_get_reg_q(timer_q, timer_r, 0);
	return rreg(reg_q);
}

static inline u32_s timer_rreg_u16(timer_qe timer_q, timer_re timer_r,
				   t16b_re byte_r) {
	u32_s reg_q = timer_get_reg_q(timer_q, timer_r, byte_r);
	return rreg_u16(reg_q);
}
